package jacob.id.ants;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.Window;
import android.widget.LinearLayout;

public class AntProjectActivity extends Activity implements SensorEventListener {
	/** Called when the activity is first created. */
	private Panel mPanel;
	private SensorManager mSensorManager;
	private Sensor mAccelerometer;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);

		mPanel = new Panel(this);
		
		((LinearLayout)findViewById(R.id.linearLayout1)).addView(mPanel);
		mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
		mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
		mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_FASTEST);
	}
	
	protected void onResume(){
		super.onResume();
		mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_FASTEST);
		
	}
	
	protected void onPause(){
		super.onPause();
		mSensorManager.unregisterListener(this);
		
	}
	
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO Auto-generated method stub
		//Do Nothing!!!!
	}
	
	public void onSensorChanged(SensorEvent event) {
		// TODO Auto-generated method stub
		float y = event.values[0];
		float x = event.values[1];
		mPanel.setAntX(((int)x));
		mPanel.setAntY((int)y);
		
	}
}











